import type { RouteObject } from "@/router/type"
// 获取路由
export const findRoute = (url: string, arr: RouteObject[]): RouteObject => {
	let result: RouteObject = {}
	arr.forEach((item) => {
		if (item.path && item.path === url) result = item
		if (item.children) {
			const res = findRoute(url, item.children)
			if (Object.keys(res).length) result = res
		}
	})
	return result
}
// 筛选路由
export const filterRoutes = (
	routes: RouteObject[],
	permissions: string[],
): RouteObject[] => {
	return routes.filter((item) => {
		if (item?.meta?.name && permissions.includes(item.meta?.name)) {
			if (item.children) {
				item.children = filterRoutes(item.children, permissions)
			}
			return true
		}
	})
}
/**
 * getTimeRegion函数用于定义当前时间处于哪个时间段（早上、上午、下午、晚上）
 * @return string
 */
export const getTimeRegion = (): string => {
	let region = ""
	const h = new Date().getHours()
	if (h >= 0 && h < 9) {
		region = "早上"
	} else if (h >= 9 && h < 12) {
		region = "上午"
	} else if (h >= 12 && h < 18) {
		region = "下午"
	} else {
		region = "晚上"
	}
	return region
}
